<?php
/**
 * Created by PhpStorm.
 * User: xujiang
 * Date: 2017/9/9
 * Time: 18:35
 */

function test(){
    $systemid = 864;
    $mode = "c";
    $permissions = 0755;
    $size = 1024;
    $shmid = shmop_open($systemid, $mode, $permissions, $size);
    return $shmid;
}

function close($shmid){
    shmop_delete($shmid);
    shmop_close($shmid);
}

function run(){
    $shmid = test();
    $i=0;
    while (1){
        sleep(3);
         $count = shmop_read($shmid,0,1);
        echo $count;
        if($count == 1){
            shmop_write($shmid, "0", 0);
            $count = shmop_read($shmid,1,2);
        }
        echo shmop_read($shmid, $i, 13);
        $i = $i+13;
        if($i >= 1000){
            close($shmid);
            break;
        }
    }
}

run();